package com.hospital.service.impl;

import com.hospital.controller.Code;
import com.hospital.controller.Result;
import com.hospital.dao.DoctorDao;
import com.hospital.domain.Doctor;
import com.hospital.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@Service
public class DoctorServiceImpl implements DoctorService {

    @Autowired
    DoctorDao doctorDao;
    @Override
    public List<Doctor> selectDoctorByCondition(String doctorName, String departmentName) {
        return doctorDao.selectDoctorByCondition(doctorName,departmentName);
    }

    @Override
    public Result login(Doctor doctor, HttpServletRequest request, HttpServletResponse response) {
        String accountNum = doctor.getAccountNum();
        String pwd = doctor.getPwd();
        Doctor doctor1 = doctorDao.login(accountNum,pwd);
        if(doctor1 == null) return new Result(Code.GET_ERR,null,"error");
        else{
            HttpSession session = request.getSession();
            session.setAttribute("doctorAccountNum",accountNum);
            session.setAttribute("doctorID",doctor1.getDoctorID());
            return new Result(Code.GET_OK,doctor1,"success");
        }
    }


    @Override
    public Integer selectRate(String doctorNum) {
        return doctorDao.selectRate(doctorNum);
    }

    @Override
    public Doctor selectDoctorByDoctorID(int doctorID) {
        return doctorDao.selectDoctorByDoctorID(doctorID);
    }


}
